package com.example.taskdemo;

import androidx.lifecycle.MutableLiveData;

import com.example.taskdemo.bean.DistrubtuionData;
import com.example.taskdemo.bean.PlayData;
import com.example.taskdemo.bean.PlayVideoData;
import com.example.taskdemo.tasks.BaseTask;
import com.example.taskdemo.tasks.DistrubutionTask;
import com.example.taskdemo.tasks.ListTask;

import java.util.ArrayList;
import java.util.List;

public class DataSingle {
    private DataSingle(){};

    private static DataSingle aiuiDataSingle;
    public synchronized static DataSingle getInstance() {
        if(aiuiDataSingle ==null){
            aiuiDataSingle = new DataSingle();
        }
        return aiuiDataSingle;
    }


    MutableLiveData<PlayData> playDataMutableLiveData;
    MutableLiveData<DistrubtuionData> distrubtuionDataMutableLiveData;
    MutableLiveData<PlayVideoData> playVideoDataMutableLiveData;
    MutableLiveData<BaseTask> baseTaskMutableLiveData;
    MutableLiveData<ListTask> listTaskMutableLiveData;

    /***************************************任务*******************************************/
    private BaseTask baseTask(){
        BaseTask b = null;
        if(baseTaskMutableLiveData ==null){
            baseTaskMutableLiveData = new MutableLiveData<>();
        }
        b = baseTaskMutableLiveData.getValue();
        if(b ==null){
            b = new BaseTask();
        }
        return b;
    }
    public void UPTaskState(BaseTask.TASKSTATE taskstate){
        BaseTask b = baseTask();
        b.setTaskState(taskstate);
        baseTaskMutableLiveData.postValue(b);
    }
    public void UPTask(BaseTask baseTask){
        if(baseTaskMutableLiveData ==null){
            baseTaskMutableLiveData = new MutableLiveData<>();
        }
        baseTaskMutableLiveData.postValue(baseTask);
    }
    /****************************************任务******************************************/


    /****************************************多任务******************************************/
    private ListTask listTask(){
        ListTask l = null;
        if(listTaskMutableLiveData ==null){
            listTaskMutableLiveData = new MutableLiveData<>();
        }
        l = listTaskMutableLiveData.getValue();
        if(l ==null){
            l = new ListTask();
        }
        return l;
    }
    public void UPListState(ListTask.LISTSTSK liststsk){
        ListTask l = listTask();
        l.setListstsk(liststsk);
        listTaskMutableLiveData.postValue(l);
    }
    public void UPListTask(List<BaseTask> list){
        ListTask l = listTask();
        l.setListTask(list);
        l.setListstsk(ListTask.LISTSTSK.STARTASK);
        listTaskMutableLiveData.postValue(l);
    }
    /****************************************多任务******************************************/

    /****************************************播放******************************************/
    private PlayData playData(){
        PlayData p = null;
        if(playDataMutableLiveData ==null){
            playDataMutableLiveData = new MutableLiveData<>();
        }
        p = playDataMutableLiveData.getValue();
        if(p ==null){
            p = new PlayData("");
        }
        return p;
    }
    public void UPPlayState(PlayData.PLAYState playState){
        PlayData p = playData();
        p.setPlayState(playState);
        playDataMutableLiveData.postValue(p);
    }
    /****************************************播放******************************************/

    /****************************************播放视频******************************************/
    private PlayVideoData playVideoData(){
        PlayVideoData p = null;
        if(playVideoDataMutableLiveData ==null){
            playVideoDataMutableLiveData = new MutableLiveData<>();
        }
        p = playVideoDataMutableLiveData.getValue();
        if(p ==null){
            p = new PlayVideoData("");
        }
        return p;
    }
    public void UPPlayViewState(PlayVideoData.PLAYVIDEOSTATE playvideostate){
        PlayVideoData p = playVideoData();
        p.setPlayvideostate(playvideostate);
        playVideoDataMutableLiveData.postValue(p);
    }
    /****************************************播放视频******************************************/



    /****************************************前往目标******************************************/
    private DistrubtuionData distrubtuionData(){
        DistrubtuionData d = null;
        if(distrubtuionDataMutableLiveData ==null){
            distrubtuionDataMutableLiveData = new MutableLiveData<>();
        }
        d = distrubtuionDataMutableLiveData.getValue();
        if(d ==null){
            d = new DistrubtuionData("");
        }
        return d;
    }
    public void UPDistribuitonState(DistrubtuionData.DISTRIBUTIONSTATE distributionstate){
        DistrubtuionData d = distrubtuionData();
        d.setDistributionstate(distributionstate);
        distrubtuionDataMutableLiveData.postValue(d);
    }
    /****************************************前往目标******************************************/



































    public MutableLiveData<ListTask> getListTaskMutableLiveData() {
        if(listTaskMutableLiveData ==null){
            listTaskMutableLiveData = new MutableLiveData<>();
        }
        return listTaskMutableLiveData;
    }

    public void setListTaskMutableLiveData(MutableLiveData<ListTask> listTaskMutableLiveData) {
        this.listTaskMutableLiveData = listTaskMutableLiveData;
    }

    public MutableLiveData<PlayData> getPlayDataMutableLiveData() {
        if(playDataMutableLiveData ==null){
            playDataMutableLiveData = new MutableLiveData<>();
        }
        return playDataMutableLiveData;
    }

    public void setPlayDataMutableLiveData(MutableLiveData<PlayData> playDataMutableLiveData) {
        this.playDataMutableLiveData = playDataMutableLiveData;
    }

    public MutableLiveData<DistrubtuionData> getDistrubtuionDataMutableLiveData() {
        if(distrubtuionDataMutableLiveData ==null){
            distrubtuionDataMutableLiveData = new MutableLiveData<>();
        }
        return distrubtuionDataMutableLiveData;
    }

    public void setDistrubtuionDataMutableLiveData(MutableLiveData<DistrubtuionData> distrubtuionDataMutableLiveData) {
        this.distrubtuionDataMutableLiveData = distrubtuionDataMutableLiveData;
    }

    public MutableLiveData<PlayVideoData> getPlayVideoDataMutableLiveData() {
        if(playVideoDataMutableLiveData ==null){
            playVideoDataMutableLiveData = new MutableLiveData<>();
        }
        return playVideoDataMutableLiveData;
    }

    public void setPlayVideoDataMutableLiveData(MutableLiveData<PlayVideoData> playVideoDataMutableLiveData) {
        this.playVideoDataMutableLiveData = playVideoDataMutableLiveData;
    }

    public MutableLiveData<BaseTask> getBaseTaskMutableLiveData() {
        if(baseTaskMutableLiveData ==null){
            baseTaskMutableLiveData = new MutableLiveData<>();
        }
        return baseTaskMutableLiveData;
    }

    public void setBaseTaskMutableLiveData(MutableLiveData<BaseTask> baseTaskMutableLiveData) {
        this.baseTaskMutableLiveData = baseTaskMutableLiveData;
    }
}
